package main

import (
	"cappy/app/service/conf"
	_ "cappy/app/service/conf/consul"
	"flag"
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"
)

func main() {
	flag.Parse()
	fmt.Println("Hello World")
	if err := conf.Init("consul"); err != nil {
		panic(err)
	}
	if err := conf.DefaultClient.WatchConf(); err != nil {
		fmt.Printf("%+v", err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
	for {
		s := <-c
		fmt.Println(fmt.Sprintf("get a signal %s", s.String()))
		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
			conf.DefaultClient.Close()
			fmt.Println("cappy exit")
			time.Sleep(time.Second)
			return
		case syscall.SIGHUP:
		default:
			return
		}
	}

}
